function checkListById(list, id) {
  // list 要检查的数据是空肯定没有
  if(!list.length) return false
  for (let index = 0; index < list.length; index++) {
     if(list[index].id === id) return list[index]
  }
  return false
}
export default {
  namespaced: true,
  state() {
    return {
      goodsList: [
        {
          id: 109323008,
          name: "四季款",
          frontDesc: "睡眠美学，品质甄选",
          price: 77,
          stock: 99,
        },
        {
          id: 109323009,
          name: "火山飘雪",
          frontDesc: "睡眠美学，品质甄选",
          price: 88,
          stock: 99,
        },
        {
          id: 109323010,
          name: "猛龙过江",
          frontDesc: "睡眠美学，品质甄选",
          price: 177,
          stock: 99,
        },
      ],
    };
  },
  mutations: {
    decreateGoods(state,goodsInfo){
      const { id, num = 1 } = goodsInfo;
      const havaInfo = checkListById(state.goodsList,id)
      // 库存 --
      havaInfo.stock -= num
    },
    increateGoods(state,payload){
        const {id, num} = payload;
        const havaInfo = checkListById(state.goodsList,id)
        if(!havaInfo) return false
        havaInfo.stock += num
    },
  }
};
